package de.leuphana.internet.view;

import java.util.Set;

import javax.servlet.ServletException;

import de.leuphana.internet.model.Buch;
import de.leuphana.internet.model.Katalog;

/**
 * Servlet implementation class KatalogServlet
 */
public class KatalogServlet extends BuchladenServlet {
	private static final long serialVersionUID = 1L;

	private Katalog katalog;

	/**
	 * Default constructor.
	 */
	public KatalogServlet() {
		super();
	}

	public void init() throws ServletException {
		katalog = (Katalog) super.getServletContext().getAttribute("katalog");
	}

	public void destroy() {
		katalog = null;
	}

	protected void druckeKopf(String titel) {
		super.druckeKopf("Buchkatalog");
	}

	@Override
	protected void druckeInhalt() {
		Set<Buch> alleBuecher = katalog.getAlleBuecher();

		out.println("<p>Buchkatalog</p>");
		out.println("<table>");

		for (Buch buch : alleBuecher) {
			out.println("<tr>");
			out.println("<td>");
			out.println("<a href=\"" + "./BuchAnzeigen.htm?isbn="
					+ buch.getIsbn() + "\">" + buch.getBuchTitel() + "\"</a>");
			out.println("</td>");
			out.println("<td>" + buch.getPreis() + " </td>");
			out.println("</tr>");
		}

		out.println("</table>");
	}

}